package com.huobao.yunying.activitys;

import java.util.List;
import java.util.Map;

import org.xutils.view.annotation.ViewInject;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.huobao.yunying.adapters.Adapter_Gonggao;
import com.huobao.yunying.base.HuobaoBaseActivity;
import com.huobao.yunying.entity.GongaoList;
import com.huobao.yunying.https.Http;
import com.huobao.yunying.https.HttpListener;
import com.huobao.yunying.https.HttpUtil;
import com.huobao.zhangying.R;

import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

public class Act_Gonggao extends HuobaoBaseActivity implements OnItemClickListener{

	@ViewInject(R.id.listview)
	private ListView listview;
	private Adapter_Gonggao adapter;
	@Override
	protected int getContentView() {
		// TODO Auto-generated method stub
		return R.layout.layout_gonggao_list;
	}

	@Override
	protected String getTitleText() {
		return "公告";
	}

	@Override
	protected void init() {
		// TODO Auto-generated method stub
		adapter = new Adapter_Gonggao(context);
		listview.setAdapter(adapter);
		listview.setOnItemClickListener(this);
		getData();
	}

	private void getData(){
		Map<String, String> map = HttpUtil.getParams("app","message","act","msgnotice");
		Http.getInstant().sendRequest(context, map, new HttpListener() {
			
			@Override
			public void onHttpSuccess(String result) {
				JSONObject jsonObject = JSON.parseObject(result);
				List<GongaoList> list = JSON.parseArray(jsonObject.getString("retval"), GongaoList.class);
				adapter.addAll(list);
			}
			
			@Override
			public void onHttpError(String error) {
				// TODO Auto-generated method stub
				
			}
		});
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
		Intent intent = new Intent(this, Act_gongao_detail.class);
		intent.putExtra("id", adapter.getItem(position).article_id);
		startActivity(intent);
	}
}
